<?php

namespace app\modules\Admin\models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;

class pickgoodscardModel extends Model
{
    protected $table = 'pickgoods_card';
    protected $primaryKey = 'id';
    protected $appends = ['type_text', 'goods_ids_array'];

    protected $hidden = [];


    protected static array $types = [
        'cash'=>'代金券',
    ];

    /**
     * @param DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function getTypeTextAttribute()
    {
        $type_text = '';
        $type_key = array_keys(self::$types);
        if(in_array($this->attributes['type'], $type_key)){
            $type_text = self::$types[$this->attributes['type']];
        }
        unset($type_key);
        return $type_text;
    }


    public function getgoodsIdsArrayAttribute()
    {
        return array_filter(explode(',', $this->attributes['goods_ids']));
    }
}